import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;

import java.io.IOException;
//单行插入
public class PutDemo {
    static Configuration conf = null;

    static {
        conf = HBaseConfiguration.create();
        conf.set("hbase.rootdir", "hdfs://192.168.126.139:9000/hbase");
        conf.set("hbase.master", "hdfs://192.168.126.139:60010");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        conf.set("hbase.zookeeper.quorum", "192.168.126.139");
    }

    public static void insert(String tableName, String rowkey, String family, String column, String cell) throws IOException {
        Put put = new Put(rowkey.getBytes());
        //HTable负责表的get put delete scan操作
        HTable table = new HTable(conf, tableName);
        put.add(family.getBytes(), column.getBytes(), cell.getBytes());
        table.put(put);
        System.out.println("插入成功");
    }


    public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException {
        insert("stu", "rw001", "info", "name", "zhangsan");
        insert("stu", "rw001", "grade", "c", "80");
    }
}